//
//  ProjectCJViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-10-31.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//
#import "ElevatorViewController.h"
#import "ProjectCJViewController.h"
#import "EmergencyViewController.h"
#import "HotChengXiangYiViewController.h"
#import "WeakEleViewController.h"
#import "StrongElecViewController.h"
#import "JiFangDianGuiViewController.h"
#import "UPSXunJianViewController.h"
#import "TranducerXunJianViewController.h"
#import "ProjectDeviceViewController.h"
#import "PeopleProjectViewController.h"
#import "AHUViewController.h"
#import "WaiLiMianMuQiangViewController.h"
@interface ProjectCJViewController ()
{
    ASIFormDataRequest *obtainFloor;
    UIImageView *blackImageView;
    UIImageView *weakBlackView;
    UIView *deviceView;//设备
}
@end

@implementation ProjectCJViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)resource//弹出界面
{
     deviceView =[[[NSBundle mainBundle]loadNibNamed:@"jdcProjectView" owner:self options:nil]lastObject];
    
    for (int i=1; i<7; i++) {
        UIButton *btn =(UIButton*)[deviceView viewWithTag:i];
        [btn.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [Appinfomation shareIstance].strongXunJianCount = 10247;
    [self resource];
	// Do any additional setup after loading the view.
    self.title = @"工程部巡检";
    NSArray *array = @[@"弱电巡检",@"强电巡检",@"设备巡检",@"垂直电梯自检记录",@"突发事件记录"];
    [self addArray:array];
    UIImage *blackImage = [UIImage imageNamed:@"黑底1"];
    blackImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    blackImageView.userInteractionEnabled = YES;
    blackImageView.image = blackImage;
    [self.view addSubview:blackImageView];
    
    UIImage *whiteImage = [UIImage imageNamed:@"工程部白底"];
    UIImageView *whiteView = [[UIImageView alloc]initWithImage:whiteImage];
    whiteView.frame = CGRectMake((scrennWidth - whiteImage.size.width)/2, (screenHeight - whiteImage.size.height)/2, whiteImage.size.width, whiteImage.size.height);
    [whiteView setUserInteractionEnabled:YES];
    [blackImageView addSubview:whiteView];
    
    UILabel *ziliaokuLB = [UILabel new];
    ziliaokuLB.text = @"强电巡检";
    ziliaokuLB.font = [UIFont systemFontOfSize:36];
    CGSize size = [ziliaokuLB.text sizeWithFont:ziliaokuLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    ziliaokuLB.frame = CGRectMake((whiteImage.size.width - size.width)/2, 20, size.width, size.height);
    [whiteView addSubview:ziliaokuLB];

    UIImage *btnImage = [UIImage imageNamed:@"资料库按钮"];
    UIImage *closeImage = [UIImage imageNamed:@"删除"];
    UIButton *clsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [clsBtn setImage:closeImage forState:UIControlStateNormal];
    clsBtn.frame = CGRectMake(whiteImage.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [clsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:clsBtn];
    for (int i = 0 ; i < 4; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.tag = i;
        btn.frame = CGRectMake((whiteImage.size.width - btnImage.size.width*2)/3*(i%2+1)+(btnImage.size.width)*(i%2), (whiteImage.size.height - ziliaokuLB.frame.origin.y - ziliaokuLB.frame.size.height - btnImage.size.height*2)/3*(i/2+1) + btnImage.size.height*(i/2) + ziliaokuLB.frame.size.height + ziliaokuLB.frame.origin.y, btnImage.size.width, btnImage.size.height);
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 0)
        {
            btnLb.text = @"强电巡检（一）";
        }
        else if(btn.tag == 1)
        {
            btnLb.text = @"强电巡检（二）";
        }
        else if(btn.tag == 2)
        {
            btnLb.text = @"机房电柜巡检";
        }
        else if(btn.tag == 3)
        {
            btnLb.text = @"热成像仪查询";
        }
        btnLb.textColor = [UIColor whiteColor];
        size = [@"啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        [btnLb setNumberOfLines:0];
        [btnLb setTextAlignment:1];
        btnLb.backgroundColor = [UIColor clearColor];
        btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*2)/2, size.width, size.height*2);
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(xunjian:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:btn];
    }
//    弱电
    weakBlackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    weakBlackView.userInteractionEnabled = YES;
    weakBlackView.image = blackImage;
    [self.view addSubview:weakBlackView];
    UIImage *whiteIG = [UIImage imageNamed:@"工程部白底"];
    UIImageView *whiteView1 = [[UIImageView alloc]initWithImage:whiteIG];
    whiteView1.frame = CGRectMake((scrennWidth - whiteIG.size.width)/2, (screenHeight - whiteIG.size.height)/2, whiteIG.size.width, whiteIG.size.height);
    [whiteView1 setUserInteractionEnabled:YES];
    [weakBlackView addSubview:whiteView1];
    
    UILabel *weakLB = [UILabel new];
    weakLB.text = @"弱电巡检";
    weakLB.font = [UIFont systemFontOfSize:36];
     size = [weakLB.text sizeWithFont:weakLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    weakLB.frame = CGRectMake((whiteIG.size.width - size.width)/2, 50, size.width, size.height);
    [whiteView1 addSubview:weakLB];
    
    UIButton *celsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [celsBtn setImage:closeImage forState:UIControlStateNormal];
    celsBtn.frame = CGRectMake(whiteIG.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [celsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView1 addSubview:celsBtn];
    for (int i = 0 ; i < 4; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.tag = i;
        btn.frame = CGRectMake((whiteIG.size.width - btnImage.size.width*2)/3*(i%2+1)+(btnImage.size.width)*(i%2), (whiteIG.size.height - weakLB.frame.origin.y - weakLB.frame.size.height - btnImage.size.height*2)/3*(i/2+1) + btnImage.size.height*(i/2) + weakLB.frame.size.height + weakLB.frame.origin.y, btnImage.size.width, btnImage.size.height);
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 0)
        {
            btnLb.text = @"弱电巡检（一）";
        }
        else if(btn.tag == 1)
        {
            btnLb.text = @"弱电巡检（二）";
        }
        else if (btn.tag == 2)
        {
            btnLb.text = @"UPS    监视主机每周巡检";
        }
        else if (btn.tag == 3)
        {
            btnLb.text = @"变频器 月度巡检";
        }
        btnLb.textColor = [UIColor whiteColor];
        size = [@"啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        [btnLb setNumberOfLines:0];
        [btnLb setTextAlignment:1];
        btnLb.backgroundColor = [UIColor clearColor];
        if (btn.tag == 2)
        {
            btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*3)/2, size.width, size.height*3);
        }
        else
        {
            btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*2)/2, size.width, size.height*2);
        }
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(ruodian:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView1 addSubview:btn];
    }
    weakBlackView.hidden = YES;
    blackImageView.hidden = YES;
}
- (void)xunjian:(UIButton *)btn
{
    [Appinfomation shareIstance].strongXunJianCount = btn.tag;
    _openFrid = 1;
    switch (btn.tag) {
            case 0:
        {
            StrongElecViewController *strong = [StrongElecViewController new];
            [self.navigationController pushViewController:strong animated:YES];
            strong.projectDelegate = self;
        }
            break;
            
            case 1:
        {
            StrongElecViewController *strong = [StrongElecViewController new];
            [self.navigationController pushViewController:strong animated:YES];
            strong.projectDelegate = self;
        }
            break;
            
            case 2:
        {
            JiFangDianGuiViewController *third = [JiFangDianGuiViewController new];
            [self.navigationController pushViewController:third animated:YES];
            third.projectDelegate = self;
        }
            break;
            
            case 3:
        {
            HotChengXiangYiViewController *hotV = [HotChengXiangYiViewController new];
            [self.navigationController pushViewController:hotV animated:YES];
        }
            break;
            default:
            break;
    }
    blackImageView.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}
- (void)ruodian:(UIButton*)btn
{
    [Appinfomation shareIstance].strongXunJianCount = btn.tag;
    _openFrid = 1;
    if (btn.tag == 0 || btn.tag ==1)
    {
        WeakEleViewController *weak = [WeakEleViewController new];
        [self.navigationController pushViewController:weak animated:YES];
        weak.projectDelegate = self;
    }
    else if (btn.tag ==2)
    {
        UPSXunJianViewController *UPs = [UPSXunJianViewController new];
        [self.navigationController pushViewController:UPs animated:YES];
        UPs.projectDelegate = self;
    }
    else if (btn.tag ==3)
    {
        TranducerXunJianViewController *trans = [TranducerXunJianViewController new];
        [self.navigationController pushViewController:trans animated:YES];
        trans.projectDelegate = self;
    }
    weakBlackView.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}
#pragma mark---Action
-(void)btnClick:(UIButton*)send
{
    [Appinfomation shareIstance].strongXunJianCount = send.tag;
    _openFrid = 1;
    switch (send.tag) {
        case 1://工程设备巡检
        {
            [Appinfomation shareIstance].strongXunJianCount = 521;
            ProjectDeviceViewController *proDVC =[[ProjectDeviceViewController alloc]init];
            [self.navigationController pushViewController:proDVC animated:YES];
            proDVC.projectDelegate = self;
        }
            break;
        case 2:
        {
            PeopleProjectViewController *ppVC =[[PeopleProjectViewController alloc]init];
            _openFrid = 0;
            [self.navigationController pushViewController:ppVC animated:YES];
            ppVC.projectDelegate = self;
        }
            break;
        case 3:
        {
            _openFrid = 0;
            AHUViewController *ahu =[[AHUViewController alloc]init];
            [self.navigationController pushViewController:ahu animated:YES];
            ahu.projectDelegate = self;
        }
            break;
        case 4:
        {
            WaiLiMianMuQiangViewController*waiLiVC =[[WaiLiMianMuQiangViewController alloc]init];
            [self.navigationController pushViewController:waiLiVC animated:YES];
            _openFrid = 0;
            waiLiVC.projectDelegate = self;
        }
            break;
        case 5:
        {
            WaiLiMianMuQiangViewController *wVC =[[WaiLiMianMuQiangViewController alloc]init];
            [self.navigationController pushViewController:wVC animated:YES];
            _openFrid = 0;
            wVC.projectDelegate = self;
        }
            break;
        case 6:
            [deviceView removeFromSuperview];
            break;
            
        default:
            break;
    }
    [deviceView removeFromSuperview];
    self.navigationController.navigationBar.hidden =NO;
}
- (void)clicked:(UIButton*)btn
{
    _openFrid = 1;
    [Appinfomation shareIstance].strongXunJianCount = btn.tag;
    switch (btn.tag) {
        case 0:
        {
            weakBlackView.hidden = NO;
            self.navigationController.navigationBar.hidden = YES;
        }
            break;
        case 1:
        {
            blackImageView.hidden = NO;
            self.navigationController.navigationBar.hidden = YES;
        }
            break;
        case 2:{
            [self.view addSubview:deviceView];//设备巡检
            self.navigationController.navigationBar.hidden =YES;
        }
            break;
        case 3:
        {
            _openFrid = 0;
            ElevatorViewController *ELEV = [ElevatorViewController new];
            [self.navigationController pushViewController:ELEV animated:YES];
            ELEV.projectDelegate = self;
        }
            break;
        case 4:
        {
            EmergencyViewController *eme = [EmergencyViewController new];
            [self.navigationController pushViewController:eme animated:YES];
        }
            break;
        case 5:
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
            
        default:
            break;
    }
}
- (void)closeV
{
    blackImageView.hidden = YES;
    weakBlackView.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
